var app = getApp();
Page({

  data: {
    pageInfo: '',
    index: 0,
    index2: 0,
    array: ['早班', '晚班'],
    array2: ['上班', '下班'],
    date: '',
    liyou:'',
    date2:''
  },

  onLoad: function () {
    var that = this;
    if (!wx.getStorageSync('openid')) {
      app.error("请登录后再操作");
      return false;
    }
    var date = new Date();

    var mingtian = date.getDate()+1

    var houtian = date.getDate()+2

    var todate = date.getFullYear() + "-" + ((date.getMonth() + 1) < 10 ? ("0" + (date.getMonth() + 1)) : date.getMonth()+1) + "-" + (mingtian < 10 ? ("0" + mingtian) : mingtian)+" 00:00:00";
    
    var todate2 = date.getFullYear() + "-" + ((date.getMonth() + 1) < 10 ? ("0" + (date.getMonth() + 1)) : date.getMonth()+1) + "-" + (houtian < 10 ? ("0" + houtian) : houtian)+" 00:00:00";

    that.setData({ start: todate}); 
    that.setData({ date: todate});
    that.setData({ date2: todate2});
    
  },
  tijiao(){
    
 
      var liyou = this.data.liyou
      var kaishi = this.data.date
      var jieshu = this.data.date2

      if(!liyou){
        wx.showModal({
          title: '温馨提示',
          content: '请输入请假理由',
          showCancel: false
        });
        return false
      }


   
    wx.request({
      url: app.apiUrl + '/api/index/antianqingjia',
      data: {
        kaishi:kaishi,
        jieshu:jieshu,
        liyou:liyou,
        openid:wx.getStorageSync('openid'),
      },
      method: 'POST',
      header: { 'content-type': 'application/x-www-form-urlencoded' },
      success: res=> {

        wx.showModal({
          title: '温馨提示',
          content: res.data,
          showCancel: false
        });
        
        setTimeout(function () {
          wx.navigateTo({
            url: '/page/my/index',
          });
        }, 2000)
    
      
      }
    })

  },
  bindKeyInput(e){
      console.log(e.detail.value)
      this.setData({ liyou: e.detail.value});
  },

  bindDateChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value+' 00:00:00'
    })
  },

  bindDateChange2: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date2: e.detail.value+' 00:00:00'
    })
  },


  bindPickerChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      index: e.detail.value
    })
  },

  bindPickerChange2: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      index2: e.detail.value
    })
  },

})